package a_aa_amainpackage.a_o2odata_deal

import org.apache.spark.sql.SQLContext
import org.apache.spark.{SparkConf, SparkContext}
import org.elasticsearch.spark._

/*
*项目名: o2odata_commend
*文件名: tm_main
*创建者: hancongcong
*创建时间:2019/8/7 11:57
*描述: TODO
*/ object b {


  def main(args: Array[String]): Unit = {


    val conf = new SparkConf()
    conf.setAppName(s"${this.getClass.getSimpleName}")
    conf.set("spark.debug.maxToStringFields", "500")
    conf.setMaster("local[*]")
    conf.set("es.nodes", "192.168.1.157")
    conf.set("es.port", "9200")
    conf.set("cluster.name", "O2OElastic")
    conf.set("spark.serializer", "org.apache.spark.serializer.KryoSerializer")
    conf.set("spark.sql.caseSensitive", "true")
    val sc = new SparkContext(conf)
    val sqlContext = new SQLContext(sc)
    sc.setLogLevel("WARN")
    sc.hadoopConfiguration.set("fs.s3a.access.key", "GAO7EO9FWKPJ8WFCQDME")
    sc.hadoopConfiguration.set("fs.s3a.secret.key", "LZ0xaHBSYKHaJ9ECDbX9f7zin79UZkXfGoNapRPL")
    sc.hadoopConfiguration.set("fs.s3a.endpoint", "https://obs.cn-north-1.myhuaweicloud.com")

    //加载十月份数据
    //val value1: RDD[String] = sc.esJsonRDD(s"2019_tmall/tmall_2019_10").values
    //val month10: DataFrame = sqlContext.read.json(value1)
    //加载预售第二次数据
    val value2 = sc.esJsonRDD(s"2019_presale_tmall/tmall_2019_shuang11_3").values
    val yushou_data = sqlContext.read.json(value2)
    //加载有问题数据
    val data = sqlContext.read.json("s3a://o2o-dataproces-group/panzonghao/equal")

    yushou_data.createOrReplaceTempView("yushou_data")
    data.createOrReplaceTempView("data")

    val result = sqlContext.sql(
      s"""
         |select
         |t1.good_id,
         |t2.priceText,
         |t1.sellCount
         |from
         |data t1
         |inner join
         |yushou_data t2
         |on t1.good_id=t2.good_id
         |where t1.priceText!='-1'
       """.stripMargin)


      .repartition(1).write.json("s3a://o2o-dataproces-group/panzonghao/yicahng_v1")

  }

  def func(s:String):String={
    var str = ""
    if (s.contains("￥")){
      str = s.split("\\￥")(1)
    }else {
      str = s
    }
    str
  }

}

















